<template>
    <div>
        <h1>病房管理</h1>
        房间名称:<input type="text" v-model="infoo.name">
        <input type="button" value="查询" @click="GetList" >
    <table class="table table-bordered" style="background-color: khaki;">
            <tbody>
                <tr>
                    <td>病房名称</td>
                    <td>病号房</td>
                    <td>所属科室</td>
                    <td>床位总数量</td>
                    <td>状态</td>
                    <td>空闲床数量</td>
                    <td>创建日期</td>
                    <td>操作</td>
                </tr>
                <tr v-for="value in info">
                    <td>{{value.roomname}}</td>
                    <td>{{value.roomid}}</td>
                    <td>{{value.oname}}</td>
                    <td>{{value.allbed}}</td>
                    <td>{{value.state==1?"启用":"维修"}}</td>
                    <td>{{value.freebed}}</td>
                    <td>{{value.createtime.substr(0,10)}}</td>
                    <td><input type="button" value="详情" @click="fan(value.id)" style="background-color: cornflowerblue;">
                      <input type="button" value="维修" class="btn btn-info" v-if="value.state==1" @click="Updatestate(value.id,0)" >
                        <input type="button" value="启用" class="btn btn-warning" v-if="value.state==0" @click="Updatestate(value.id,1)" >
                        </td>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import {ref} from 'vue'
import axios from 'axios';
import { onMounted } from 'vue';
import { useRoute,useRouter } from 'vue-router';
let route=useRoute();
let router=useRouter();

let info:any=ref([]);
let infoo:any=ref({
    name:"",
})
onMounted(()=>{
    GetList();
})

const Updatestate=(id:any,state:any)=>{
     console.log('id=',id,'state=',state)
     let f=confirm("确认要修改吗?")
     if(f==true){
        axios({
            url:'https://localhost:7118/api/Room/UpdateStateRoom',
            method:'get',
            params:{
                id:id,
                state:state
            }
        })
        .then((res)=>{
            console.log(res)
            if(res.data>0){
                alert("修改成功");
                GetList();
            }
            else{
                alert("修改失败")
                return;
            }
        })
        .catch((err)=>{
            console.log(err);
        })
     }
}


const GetList=()=>{
    axios({
        url:'https://localhost:7118/api/Room/GetRoom',
        method:'get',
        params:infoo.value   
    })
    .then((res)=>[
        console.log(res),
        info.value=res.data
    ])
    .catch((err)=>{
        console.log(err);
    })
}
//跳转详情
const fan=(id:any)=>{
    router.push({
        path:'/roomfan',
        query:{
            id:id
        }
    })
}
</script>

<style scoped>

</style>

